import React from 'react';
import './index.css';
import moment from 'moment';
//CSS 模块文件导入
import CSS from './test.module.css';

class Clock extends React.Component{

    state = {
        timeStr: moment().format('YYYY-MM-DD HH:mm:ss')
    }

    render(){  
        return <div className="clock-container">
            <span className={CSS.text}>{this.state.timeStr}</span>
        </div>
    }

    componentDidMount(){
        console.log(this.props);
        //启动定时器
        this.timer = setInterval(() => {
            this.setState({
                timeStr: moment().format('YYYY-MM-DD HH:mm:ss')
            })
        }, 1000)
    }

    componentWillUnmount(){
        clearInterval(this.timer);
    }

}

export default Clock;